<template>
  <div class=''>
    <!-- 按钮 -->
    <div class="btns">
      <div style="text-align:center">
        <el-form size="small" inline :model="param"> 
          <el-form-item label="名称">
            <el-input v-model="param.name"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button  type="primary" icon="el-icon-search" @click="loadDatasets">搜索</el-button>
          </el-form-item>
        </el-form>
      </div>
        <el-button type="primary" size="small" width="150" icon="el-icon-plus" @click="toAddHandler">新增</el-button>
        <el-button type="primary" size="small" width="150" icon="el-icon-upload" @click="downloadHandler">导出</el-button>
    </div>
    <!-- 按钮 -->
    <el-table size="small" :data="datasets">
      <el-table-column label="序号" type="index" :index="1" width="60" align="center"></el-table-column>
      <el-table-column label="封面" prop="photo" align="center" width="200px">
        <template slot-scope="scope">
          <div style="width:160px;border-radius:5px;height:80px;over-flow:hidden" >
            <img :src="scope.row.photo" alt="" style="width:100%">
          </div>
        </template>
      </el-table-column>
      <el-table-column label="信息">
        <template slot-scope="scope">
          <p>{{scope.row.name}}</p>
          <p>{{scope.row.introduce}}</p>
          <p>{{scope.row.photo}}</p>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="300px" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="toEnterHandler(scope.row)">修改</el-button>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="deleteHandler(scope.row)">删除</el-button>
          <el-button type="primary" size="mini" icon="el-icon-top-right" @click="enterHandler(scope.row)">跳转</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
</template>
<script>
import { del, get } from "@/utils/request";
export default {
  //页面数据
  data() {
    return {
      param: {},
      datasets: [],
    };
  },
  //页面渲染的时候会调用的函数
  methods: {
     downloadHandler(){
      window.location.href = "http://localhost:8888/dataset/download?name="+this.param.name
    },
    enterHandler(row){
      this.$router.push({
        path:"/datasetFile/index",
        query:{datasetId:row.Id}
      })
    },
    toEnterHandler(row){
      this.$router.push({
        path:"/dataset/create",
        query:row,
      })
    },
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://localhost:8888/dataset/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadDatasets();
        });
      });
    },
    // 跳转
    toAddHandler() {
      this.$router.push("/dataset/create");
    },

    loadDatasets() {
      let url = "http://localhost:8888/dataset/query";
      get(url, this.param).then((resp) => {
        this.datasets = resp.data;
      });
    },
  },
  created() {
    this.loadDatasets();
  },
};
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
}
</style>
